package cn.ibizlab.odoo.core.odoo_mail.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Imail_blacklist_mixin;
import cn.ibizlab.odoo.core.odoo_mail.domain.Mail_blacklist_mixin;
import cn.ibizlab.odoo.core.odoo_mail.filter.Mail_blacklist_mixinSearchContext;
import cn.ibizlab.odoo.core.odoo_mail.service.IMail_blacklist_mixinService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[mixin邮件黑名单] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Mail_blacklist_mixinServiceImpl implements IMail_blacklist_mixinService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Imail_blacklist_mixinClientService mail_blacklist_mixinClientService;

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Imail_blacklist_mixin clientModel = mail_blacklist_mixinClientService.createModel();
        clientModel.setId(id);
        mail_blacklist_mixinClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Mail_blacklist_mixin> mail_blacklist_mixins, int batchSize) {

                        //mail_blacklist_mixinClientService.createBatch(mail_blacklist_mixins,batchSize) ;

    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //mail_blacklist_mixinClientService.removeBatch(mail_blacklist_mixins) ;

    }

    @Override
    public boolean update(Mail_blacklist_mixin mail_blacklist_mixin) {
        boolean bOk = false ;
        Imail_blacklist_mixin clientModel = this.convert2Model(mail_blacklist_mixin,null);
        mail_blacklist_mixinClientService.update(clientModel) ;
        this.convert2Domain(clientModel,mail_blacklist_mixin) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void updateBatch(List<Mail_blacklist_mixin> mail_blacklist_mixins, int batchSize) {

        //mail_blacklist_mixinClientService.updateBatch(mail_blacklist_mixins,batchSize) ;

    }

    @Override
    public Mail_blacklist_mixin get(Integer id) {
        Imail_blacklist_mixin clientModel = mail_blacklist_mixinClientService.createModel();
        clientModel.setId(id);
        mail_blacklist_mixinClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Mail_blacklist_mixin get(Mail_blacklist_mixin mail_blacklist_mixin) {
        Mail_blacklist_mixin retmail_blacklist_mixin = this.get(mail_blacklist_mixin.getId()) ;
    	BeanCopier copier=BeanCopier.create(retmail_blacklist_mixin.getClass(), mail_blacklist_mixin.getClass(), false);
        copier.copy(retmail_blacklist_mixin, mail_blacklist_mixin, null);
        return mail_blacklist_mixin ;
    }

    @Override
    public boolean create(Mail_blacklist_mixin mail_blacklist_mixin) {
        boolean bOk = false ;
        Imail_blacklist_mixin clientModel = this.convert2Model(mail_blacklist_mixin,null);
        mail_blacklist_mixinClientService.create(clientModel) ;
        this.convert2Domain(clientModel,mail_blacklist_mixin);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Mail_blacklist_mixin> searchDefault(Mail_blacklist_mixinSearchContext context) {
        List<Mail_blacklist_mixin> list = new ArrayList<Mail_blacklist_mixin>();
        Page<cn.ibizlab.odoo.core.client.model.Imail_blacklist_mixin> clientModelList = mail_blacklist_mixinClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Imail_blacklist_mixin clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Mail_blacklist_mixin>(list, context.getPageable(), clientModelList.getTotalElements());
    }




    public Imail_blacklist_mixin convert2Model(Mail_blacklist_mixin domain , Imail_blacklist_mixin model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = mail_blacklist_mixinClientService.createModel() ;
        }

         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getIs_blacklistedDirtyFlag())
            model.setIs_blacklisted(domain.getIs_blacklisted());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
        return model ;
    }

    public Mail_blacklist_mixin convert2Domain( Imail_blacklist_mixin model ,Mail_blacklist_mixin domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Mail_blacklist_mixin();
        }

        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getIs_blacklistedDirtyFlag())
            domain.setIs_blacklisted(model.getIs_blacklisted());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        return domain ;
    }


}
